home *** CD-ROM | disk | FTP | other *** search
/ OctaMED Sound Studio 1 / OctaMED SoundStudio V1.iso / soundstudio v1 / programmers / proplayer.doc < prev    next >
Text File  |  1996-06-18  |  16KB  |  438 lines

  1. INTRODUCTION TO OCTAMED PLAYER ROUTINES
  2. =======================================
  3.  
  4. This drawer contains the material, which is required for using OctaMED
  5. music in your own programs. You are allowed to freely use these routines in
  6. your own non-commercial programs. For commercial products, you will have to
  7. licence the routines. (See the files ReadMe.doc and Licence.doc for the
  8. details.)
  9.  
  10. You have basically two choices - you can either incorporate the player
  11. routine (written in assembler) to your program, or you can use the provided
  12. external player libraries.
  13.  
  14. 1. Embedded player routines (proplayer/pro8player/promixplayer)
  15.  
  16. These are the most often used routines. They are usually the best choice
  17. for embedded game music, module player programs etc. Easy switches are
  18. provided for turning off unnecessary features. As the assembler source is
  19. provided, you can modify the code or add hooks to suit your specific
  20. purpose. The rest of this document contains instructions for the proplayer
  21. routines.
  22.  
  23. 2. Player libraries (medplayer.library/octaplayer.library/
  24.     octamixplayer.library)
  25.  
  26. These are shared libraries that any application program may call. (Only one
  27. task can be using them at a time, though.) The libraries contain basically
  28. the same functionality as proplayer routines, but no tailoring can be made.
  29. An obvious advantage is that library upgrades are transparent to your
  30. application. The user can simply replace the libraries. See the file
  31. Library.doc for details on using the libraries.
  32.  
  33. Note: medplayer.library and octaplayer.library are located in the LIBS
  34. drawer of this disk.
  35.  
  36. Note: If you need a feature that currently does not exist, send us your
  37. exact requirements, and we'll do our best to help you.
  38.  
  39.     Instructions for using "proplayer.a", the stand-alone playroutine.
  40. ===========================================================================
  41.  
  42. "proplayer" is a piece of code which is linked with your program and plays
  43. four channel MED and OctaMED modules (with optional MIDI).
  44.  
  45. "proplayer" contains the following routines:
  46.     InitPlayer
  47.     RemPlayer
  48.     PlayModule
  49.     ContModule
  50.     StopPlayer
  51.     SetTempo
  52.  
  53. The arguments are passed in registers, and return values are returned in d0.
  54. These routines will trash registers d0-d1 and a0-a1.
  55.  
  56. And now the descriptions of each one:
  57. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  58. InitPlayer -- initialize everything
  59.  
  60. Before you can call the other functions, you must call this function.
  61. It allocates the audio channels, timer, serial port (if MIDI) etc...
  62.  
  63. ARGUMENTS:    none
  64.  
  65. RETURNS:    0 if everything is ok, otherwise something failed.
  66.         If something failed, you can still call the other
  67.         routines - they just don't do anything.
  68.  
  69. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  70. RemPlayer -- return everything back
  71.  
  72. Call this when your program exits. It frees the audio channels, timer,
  73. serial port etc.
  74.  
  75. ARGUMENTS:    none
  76.  
  77. RETURNS:    nothing
  78.  
  79. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  80. PlayModule -- start playing a module
  81.  
  82. When you want to start playing, call this routine.
  83.  
  84. ARGUMENTS:    a0 = pointer to the module. See below for instructions
  85.         how to obtain the pointer.
  86.  
  87. RETURNS:    nothing
  88.  
  89. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  90. StopPlayer -- stop playing
  91.  
  92. ARGUMENTS:    no arguments
  93.  
  94. RETURNS:    nothing
  95.  
  96. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  97. ContModule -- continue playing
  98.  
  99. This routine continues playing the module from the point it was stopped.
  100.  
  101. ARGUMENTS:    a0 = pointer to the module
  102.  
  103. RETURNS:    nothing
  104.  
  105. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  106. SetTempo -- set the playback tempo
  107.  
  108. (This routine has not much use.)
  109.  
  110. ARGUMENTS:    d0 = new tempo (1 - 240)
  111.  
  112. RETURNS:    nothing
  113.  
  114. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  115.  
  116. "proplayer.a" is the source code of the music routine. It contains stuff
  117. that may be unnecessary for your purposes, just taking time and memory.
  118. There are some "switches" at the beginning of the source, that allow you
  119. to turn off features you don't need. They are:
  120.  
  121. MIDI        If only the Amiga audio channels are used, set this to 0.
  122. AUDDEV        For some purposes, you may want to disable the code that
  123.         allocates the audio channels using "audio.device", e.g.
  124.         in a non-multitasking environment. Normally this should
  125.         be 1.
  126. SYNTH        If synth/hybrid sounds are not in use, this can be set to
  127.         zero.
  128. CHECK        This does some checkings to ensure that several values are
  129.         correct (e.g. is the sample in memory, no Amiga effects on
  130.         MIDI-tracks etc..). If you know that the song is correct,
  131.         you can safely turn the checks off.
  132. RELVOL        If you don't need the "relative volume", this can be zero.
  133. IFFMOCT        If the song doesn't contain multi-octave IFF samples
  134.         this can be zero.
  135. HOLD        This turns off the hold/decay features.
  136. PLAYMMD0    If set, the play routine will also handle old MMD0 type
  137.         modules. Useful for player programs.
  138. FASTMEMPLAY    If you don't need FastMem playing, you can set this to 0
  139.         to save some code space.
  140. AURA        Aura output can be enabled by using this flag. (The file
  141.         "aura.a" must exist.)
  142.  
  143.  
  144. "proplayer.a" also supports multi-modules. It defines a UWORD modnum
  145. (in assembler: _modnum). Set this variable to the number of the song
  146. you want to play before calling PlayModule (0 is the first, 1 is the
  147. second song etc..). For example:
  148.     #include "proplayer.h" /* defines 'modnum' */
  149.     ...
  150.     modnum = 1; /* Play the second module */
  151.     PlayModule(module);
  152.     ...
  153. Assembler:
  154.     xref    _modnum
  155.     xref    _PlayModule
  156.     ...
  157.     move.w    #1,_modnum
  158.     lea    _module,a0
  159.     jsr    _PlayModule(pc)
  160.     ...
  161.  
  162. FastMem Playing
  163. ===============
  164. It's now possible to play samples from the fast memory (also allowing long
  165. samples and odd repeat offset/length). For this purpose, two other UWORDs
  166. are defined in the routine: _fastmemplay must be set to 1 in order to
  167. activate this feature. Also, you can also change the buffer size of FastMem
  168. playing with the _fmp_buffsize symbol. Buffer size must be divisible by 4
  169. and no more than 400. (Default: 64).
  170.  
  171. Timing
  172. ======
  173. If you need vertical blanking timing, you can set VBLANK to 1 and CIAB to 0.
  174. In normal use this is not recommended (because of the 16 % difference in
  175. playing speed with NTSC and PAL Amigas), but if tight synchronization to
  176. vertical blanking (e.g. in most demos/games) is required, VBLANK can be
  177. used.
  178.  
  179. For VBlank timing, the song has to be composed with primary tempo of about
  180. 33. The primary tempo cannot be changed with command F. Only the secondary
  181. tempo control can be used (command 9).
  182.  
  183. Assembling
  184. ==========
  185. "proplayer.a" can be assembled by using HiSoft's Devpac Assembler without
  186. changes. Other assemblers may need some small changes to work correctly
  187. (mostly because the directives they support may be slightly different). If
  188. you're working on a linker environment (e.g. programming in C), you've to
  189. include the resulted "proplayer.o" in your .lnk-file.
  190.  
  191. ===========================================================================
  192.  
  193. And how to get some music?
  194.  
  195. You have two ways to get the music:
  196. 1. Include the module in your final executable.
  197. 2. Save the module as a separate disk file and load it when needed
  198.    (this is probably the best way if you have more than one song, and
  199.     you don't want to use multi-modules).
  200.  
  201. First I cover the first method:
  202. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  203. Including the module in your final executable:
  204.  
  205. There's a utility, Objconv, which loads the module and dumps it into an
  206. object file. Here's an example how to use it:
  207.  
  208. - Assemble 'reloc.a' to 'reloc.o'.
  209. - Save the song as a module
  210. - Use Objconv e.g. objconv medmodule mod.o
  211. - Objconv requests the symbol name, enter "song" (without "'s), for example.
  212. - Now there's a file 'mod.o'. Link this file, and the file 'reloc.o'
  213.   with your program.
  214. - In your program, you define the module:
  215.     #include "proplayer.h"
  216.     ...
  217.     extern struct MMD0 far song;
  218.   You must relocate the module before it's used. Do this only once!
  219.   This is done by
  220.     RelocModule(&song);
  221.   RelocModule expects the argument in stack, so use __stdargs, if you've
  222.   turned registerized parameters on.
  223.  
  224. In assembler, you'd do exactly in the same way, except:
  225.     xref    _song
  226.     xref    _RelocModule
  227.     xref    _PlayModule
  228.  
  229.     ... (assuming all init stuff is here)
  230.  
  231.     lea    _song,a0
  232.     move.l    a0,-(sp)    ;push into stack
  233.     jsr    _RelocModule(pc)
  234.     addq.l    #4,sp        ;reset stack pointer
  235.     lea    _song,a0    ;this is passed in register a0
  236.     jsr    _PlayModule
  237.     ...
  238.  
  239. Note: if you've got an assembler that supports 'incbin' directive or
  240. equivalent, you can use it instead of Objconv. Relocation is required in
  241. any case.
  242.  
  243. And the second method (loading modules from disk):
  244. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  245. File "loadmod.a" contains four routines:
  246.     LoadModule/LoadModule_Fast
  247.     UnLoadModule
  248.     RelocModule
  249.     RequiredPlayRoutine
  250.  
  251. You usually need only the first two of them. RelocModule is used by
  252. LoadModule.
  253.  
  254. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  255. LoadModule/LoadModule_Fast -- loads a module from disk
  256.  
  257. This function loads a module from disk. Note that relocation is done
  258. automatically, so you must not RelocModule() a module obtained by using
  259. this routine.
  260.  
  261. Note: LoadModule_Fast is new as of OctaMED Soundstudio. OctaMED Soundstudio
  262. sets a flag in the main MMD structure if the module can be always loaded
  263. into fast RAM (i.e. if it uses mixing, only MIDI or 8-ch mode). If this
  264. flag is set, both routines load the module into fast RAM. LoadModule_Fast
  265. always loads the module into fast RAM, you need to use the FastMemPlay
  266. feature to play 4-channel or 5-7 channel modules in that case.
  267.  
  268. ARGUMENTS:    a0 = pointer to file name
  269.  
  270. RETURNS:    d0 = pointer to the module, if something failed: 0
  271.  
  272. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  273. UnLoadModule -- free the module from memory
  274.  
  275. Frees the module. Remember to StopPlayer() before you unload the module
  276. that is currently playing. Also remember to free all modules you've loaded
  277. before you exit the program.
  278.  
  279. ARGUMENTS:    a0 = pointer to the module (may be 0)
  280.  
  281. RETURNS:    nothing
  282.  
  283. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  284. RequiredPlayRoutine -- find out which routine is required for this module
  285.  
  286. Checks the flag bits in the module to find out which playing routine
  287. you should use. If you can't/don't want to support the playing routine
  288. this function tells you, you had better refrain from playing the module
  289. altogether, rather than using a wrong routine.
  290.  
  291. ARGUMENTS:    a0 = pointer to the module (may be 0, in which case this
  292.              routine returns zero).
  293.  
  294. RETURNS:    One of these values:
  295.         0 = use 4 channel routine (proplayer), or no module
  296.         1 = use 5-8 channel routine (pro8player)
  297.         2 = use mixing routine (promixplayer)
  298.  
  299. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  300. FastMemPlayRecommended -- should FastMemPlay used...?
  301.  
  302. In addition to playing modules from Fast RAM, FastMemPlay removes some
  303. restrictions: the sample length limitation of 131072 bytes, and loop
  304. granularity of 2 bytes. This routine checks whether the module uses
  305. either of these extensions. If it returns TRUE, you should activate
  306. FastMemPlay in order to be able to fully reproduce the module. If FALSE
  307. is returned, the module plays perfectly even without FastMemPlay (if it's
  308. in Chip RAM). Note: If at all possible, you should not keep FastMemPlayed
  309. modules in Chip memory; they play much more efficiently from Fast RAM.
  310.  
  311. ARGUMENTS:    a0 = pointer to the module (may be 0)
  312.  
  313. RETURNS:    0 = plays perfectly without FastMemPlay
  314.         1 = may not play perfectly without FastMemPlay
  315.  
  316. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  317.  
  318. ===========================================================================
  319.  
  320. REMEMBER:    All functions expect the arguments in registers. This is
  321.         automatically (??) handled by you when you program in
  322.         assembler, but it is not automatically handled when
  323.         you're programming in C.
  324.  
  325. If you have SAS/C V5 or later, this is done automatically if you include
  326. "proplayer.h" in all your code modules which call proplayer. If you have a
  327. compiler which doesn't support argument passing in registers, then you have
  328. to write the stub routines in assembler.
  329.  
  330. See also the small example sources.
  331.  
  332. File formats
  333. ============
  334. The playing routines can be used to play all MMD formats saved by OctaMED
  335. or late versions of MED. (Set PLAYMMD0 for MMD0 support.) The currently
  336. supported formats are MMD0, MMD1, MMD2, MMD3.
  337.  
  338. MMD3?
  339. =====
  340. Although not mentioned in OctaMED itself, modules using mixing are saved
  341. using the MMD3 format, which is identical to MMD2. The reason for this is
  342. that old module players might choke if attempting to load a module that
  343. uses mixing. *HOWEVER* MMD3 does NOT imply mixing!! You must always check
  344. the required play routine with RequiredPlayRoutine, even with MMD3 modules.
  345. MMD3 supporting programs should just be aware of the new Soundstudio mixing
  346. mode, and fail if they can't/don't want to support it.
  347.  
  348. ===========================================================================
  349.  
  350.     pro8player.a
  351.     ~~~~~~~~~~~~
  352.  
  353. "pro8player.a" is the play-routine for OctaMED 5 - 8 channel songs. This
  354. can be used exactly in the same way as "proplayer.a". The functions just
  355. have slightly different names:
  356.     InitPlayer8
  357.     RemPlayer8
  358.     PlayModule8
  359.     ContModule8
  360.     StopPlayer8
  361.     modnum8
  362.  
  363. Note that this player have some restrictions, as opposed to "proplayer.a".
  364. They're listed in OctaMED documents. It also takes quite a lot of processor
  365. time, depending on how many splitted channels there are.
  366.  
  367. You can use the same RelocModule() and (Un)LoadModule() routines with
  368. 5 - 8 channel songs.
  369.  
  370. The eight channel player has a byte flag _hq (assembler)/hq (C), which
  371. controls the HQ mode. Set this to 1 prior to calling PlayModule8 to
  372. activate the HQ mode.
  373.  
  374. ===========================================================================
  375.  
  376.     promixplayer.a
  377.     ~~~~~~~~~~~~~~
  378.  
  379. This is the player routine for OctaMED Soundstudio modules using the 1-64
  380. Ch mixing mode. Although it's internally rather complex, it should be as
  381. easy to use as the other two routines. The functions are analoguous to the
  382. other routines, their names are:
  383.     InitPlayerM
  384.     RemPlayerM
  385.     PlayModuleM
  386.     ContModuleM
  387.     StopPlayerM
  388.  
  389. However, a difference exists: PlayModuleM does some memory allocations for
  390. mixing buffers, echo buffers etc. It returns a success value in D0. If the
  391. return value is zero, the playing has been started successfully. Otherwise
  392. a memory allocation error has occurred.
  393.  
  394. This player routine has several user-settable variables (C users should
  395. omit the leading underscore):
  396. (UWORD)    _modnumm    Module number, as in other routines.
  397. (ULONG)    _mixbuffsize    Desired mixing buffer size (must be divisible
  398.             by 4!). [default 1024]
  399. (ULONG)    _mixfreq    Desired mixing frequency in Hz (values below 1000
  400.             are not recommended, nor are values exceeding the
  401.             maximum output frequency depending on the screen
  402.             mode). Max. value 65535. [default 15000]
  403. (UBYTE)    _mix14bit    If set, uses 14-bit output (otherwise 8-bit).
  404.             [default set]
  405.  
  406. IMPORTANT: This routine uses utility.library 32-bit math functions, and
  407. therefore requires Kickstart V36 or later.
  408.  
  409. The actual mixing routine is located in a different file (med-mixasm.a).
  410. You should set the flags provided in that file according to your desired
  411. target processor (68000, 68020+ or both). I have to admit that the 68000
  412. is usually far too slow for mixing, though, but this option is available
  413. so that A500 owners can't complain... You have been warned.
  414.  
  415. The SUPPORT_000 and SUPPORT_020 flags work as follows:
  416.  
  417. Only SUPPORT_000 set:
  418.     Works with all processors. With 68020 or higher not as fast as
  419.     it could be.
  420.  
  421. Only SUPPORT_020 set:
  422.     Does not work with 68000/010. Optimized for 68020+.
  423.  
  424. Both flags set:
  425.     Works with all processors. Uses the optimal routine. Consumes
  426.     about 3 kilobytes more memory.
  427.  
  428.  
  429. Med-mixasm.a also provides an optional smoothing routine. As the smoothing
  430. routine is provided mainly for recording to disk (not supported by the
  431. external playing routines), it's probably not useful (except for 68060
  432. owners...?) due to the fact that it's very slow. Set the SUPPORT_SMOOTH
  433. flag if you want to use it. Also, you have to call the _MixSmooth routine
  434. (D0 = 0 or 1 for off/on) to turn the smoothing on.
  435.  
  436. ===========================================================================
  437.  
  438.